<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,target-densitydpi=high-dpi,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <script src="js/jquery-3.3.1.js"></script>
    <script src="js/loading.js"></script>
    <script src="js/jquery.cookie.js"></script>
    <script src="js/commonTool.js"></script>
    <script>
    $(function(){
        $("#header").load("header.html");
        var addToken=Tool.addTokenToParams;
        $.ajax({
    		  type: 'POST',
    		  url: doTargetGet,
    		  contentType:"application/json;charset=UTF-8",
    		  data:JSON.stringify(addToken({})),
    		  xhrFields: {
    		  withCredentials: true
    		           },
    		  crossDomain: true,
    		  success: function(result){
                  console.log(result);
                  var data=result.data;
                  if(!Array.isArray(data)){
                        return;
                    }
            
                  var sumTargets=data.length;
                  $("#tarSum").text(sumTargets+"个");
                  var c_notApprove=0;
                  var c_refuse=0;
                  var c_inprogress=0;
                  var c_complete=0;
                  for(var i=0;i<sumTargets;i++){
                      var tar=data[i];
                      var tar_stat=tar.targetStatus;
                      switch(tar_stat){
                          case "0":
                            c_notApprove++;
                            break;
                          case "-1":
                            c_refuse++;
                            break;
                          case "1":
                            c_inprogress++;
                            break;
                          case "2":
                            c_complete++;
                            break;
                          default:
                            break;
                      }
                  }
                  $("#tarNotApprove").text(c_notApprove+"个");
                  $("#tarRefuse").text(c_refuse+"个");
                  $("#tarInProgress").text(c_inprogress+"个");
                  $("#tarComplete").text(c_complete+"个");          
                          
    		  },error : function(xhr, errorType, error) {
    				alert(errorType + ', ' + error);   
              }});
        $("#content_cont").find("span").click(function(){
           var currentId=$(this).attr("id");
            console.log(currentId);
            //实现跳转相应的状态页面
           var segIndex="0"; //默认是跳转到所有的选项
           if(currentId=='tarNotApprove'){
                segIndex="1";
           }else if(currentId=='tarRefuse'){
                segIndex="2";
           }else if(currentId=='tarInProgress'){
                segIndex="3";
           }else if(currentId=='tarComplete'){
                segIndex="4";
           }
           if(segIndex=="0"){
                $.removeCookie('tarIndex');
           }else{
                $.cookie('tarIndex',segIndex);
           }
           window.location="targetlist.html";
        });
    
     });
    </script>
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/mainstyle.css">
    <style>
        #content_tit{
            height: 30px;
            width: 100%;
            background-color: dodgerblue;
            
        }
        #content_tit span{
            color: white;
            margin-left: 10px;
        }
        #content_cont{
            padding: 20px 20px;
            
        }
        #content_cont span{
            color: red;
            text-decoration: underline;
        }
    </style>
    <title>首页</title>
</head>
<body>
  <div id="header"></div>  
  <div id="content">
    <div id="content_tit">
        <span>首页</span>
    </div>
    <div id="content_cont">
        <h3>任务汇总:</h3>
        <p>任务数量: <span id="tarSum">0个</span><br></p>
        <h3>未审批:</h3>
        <p>数量: <span id="tarNotApprove">0个</span></p>
        <h3>退回:</h3>
        <p>数量: <span id="tarRefuse">0个</span></p>
        <h3>进行中:</h3>
        <p>数量: <span id="tarInProgress">0个</span></p>
        <h3>已完成:</h3>
        <p>数量: <span id="tarComplete">0个</span></p>
    </div>
  </div>
</body>
</html>